
(function () {
    'use strict';

    angular.module('KingAdmin.pages.pdev.camera')
        .controller('CameraCtrl', CameraCtrl);

    /** @ngInject */
    function CameraCtrl($scope, $stateParams, $state,$uibModalInstance, CameraService, DictService, DeviceService) {
        var kt = this;
        kt.camera = {};
        kt.title = '编辑摄像头';

        if($stateParams.id){
            if ($stateParams.isView) {
                kt.isView = true;
                kt.title = '查看摄像头';
            }

            CameraService.getInfo({id:$stateParams.id},
                function (data) {
                kt.camera = data;
            })
        }else{
            kt.isAdd = true;
            kt.title = '添加摄像头';
            kt.camera = {
                port: 80,
                imageH: 720,
                imageW: 1280,
                user: 'admin',
                pass: 'admin12345',
                isActive: 0
            };
        }

        kt.devList = [];
        DeviceService.getDictList(function (data) {
            kt.devList = data.result;
            kt.isShowDev = true;
        });

        kt.devstatus = [];
        DictService.getList('DEVICESTATUS',function (data) {
            kt.devstatus = data.result;
            kt.isShowStatus = true;
            // $scope.$digest();
        });




        kt.save = function () {
            CameraService.save(kt.camera,function (data) {
                $uibModalInstance.close(true);
            });
        };

        $uibModalInstance.rendered.then(function() {

        });
    }

})();
